<!-- Type System tabs -->
<script>
  var $tabs, $toggles, ACTIVE_CLASS;

  ACTIVE_CLASS = 'js-is-active';

  $tabs = $("[data-role='tab']");

  $toggles = $tabs.find("[data-role='link']");

  $toggles.on('click', function(event) {
    var $tab, $toggle;
    event.preventDefault();
    $toggle = $(this);
    $tab = $toggle.closest($tabs);
    if (!$tab.hasClass(ACTIVE_CLASS)) {
      $tabs.removeClass(ACTIVE_CLASS);
      return $tab.addClass(ACTIVE_CLASS);
    }
  });
</script>

<!-- Show Code -->
<script>
  $('a.js-show-code').on('click', function(e){
    $(this).hide();
    $(this).siblings('.js-hide-code').css('display', 'inline-block');
    $(this).parent().siblings('.snippets-table').show();
    e.preventDefault();
  })

  $('a.js-hide-code').on('click', function(e) {
    $(this).hide();
    $(this).siblings('.js-show-code').css("display", "inline-block");
    $(this).parent().siblings('.snippets-table').hide();
    e.preventDefault();
  });
</script>

<!-- Copy Code -->
<script>
  $(document).ready( function() {
    client = new ZeroClipboard($('.copy-source'), {moviePath: '/images/ZeroClipboard.swf'})
    client.on('dataRequested', function(client, args) {
      if ($(this).hasClass("copy-coffee")) {
        var cell = $(this).parents("tr").find("td.snippet").last();
      } else {
        var cell = $(this).parents("td.snippet");
      }

      var code = cell.children("pre").text();
      client.setText(code);
    });
  });
</script>

<script>
  $(document).ready(function(){

    $('.js-menu-trigger-refills').on('click touchstart', function(e){
      $('.er_toc').toggleClass('is-visible');
      $('.js-menu-screen-refills').toggleClass('is-visible');
      e.preventDefault();
    });

    $('.js-menu-screen-refills').on('click touchstart', function(e){
      $('.er_toc').toggleClass('is-visible');
      $('.js-menu-screen-refills').toggleClass('is-visible');
      e.preventDefault();
    });
  });
</script>
